<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // var str = '<div class="box" id="test"><span></span></div>';
        // // 非贪婪模式 

        // var res = /<div .*?>/;
        // console.log(res.exec(str)[0]); // <div class="box" id="test">
        // var res1 = /<div .*>/;
        // console.log(res1.exec(str)[0]);// <div class="box" id="test"><span></span></div>

        var str2 = '<div class="box" id="test></div><div class="kangbazi"></div>';
        var res2 = /<div .*>.*<\/div>/;
        console.log(res2.exec(str2)[0]); // <div class="box" id="test></div><div class="kangbazi"></div>
        
        var res3 = /<div .*?>.*?<\/div>/;
        console.log(res3.exec(str2)[0]); // <div class="box" id="test></div><div class="kangbazi"></div>
            
    </script>
</body>
</html>